{extend name='../../admin/view/table'}

{block name="button"}

<button data-modal='{:url("add")}' data-title="添加" class='layui-btn layui-btn-sm layui-btn-primary'>添加</button>

{/block}
{block name="content"}
<div class="think-box-shadow">
    {include file='cassette/search'}
    <table id="RoleTable" data-url="{:request()->url()}" data-target-search="form.form-search"></table>
</div>
{/block}

{block name='script'}
<script>
    $(function () {
        // 初始化表格组件
        $('#RoleTable').layTable({
            even: true,
            skin : "line",
            limit : 15,
            size : 'lg',
            sort: {field: 'id', type: 'desc'},
            cols: [[
                // {checkbox: true, fixed: true},
                {field: 'id', title: '{:lang("ID")}', align: 'center', width: 100, sort: true,},
                {field: 'merchant', title: '{:lang("商家")}', align: 'center',templet: function (d) {
                        return d.merchant ? d.merchant.name : ''
                }},
               
                {field: 'name', title: '{:lang("名称")}', align: 'center'},
               
                {field: 'thumb', title: '{:lang("封面")}', align: 'center', templet: function (d) {
                        return '<img src='+d.thumb+' style="width:60px;height:60px" />'
                }},
                {field: 'price', title: '{:lang("价格")}', align: 'center'},
                {field: 'max_num', title: '{:lang("人数")}', align: 'center'},
         
                {field: 'sort', title: '{:lang("排序")}', align: 'center'},
                {field: 'status', title: '{:lang("状态")}', align: 'center', minWidth: 110, templet: '#StatusSwitchTpl'},
                {toolbar: '#toolbar', title: '{:lang("操作面板")}', align: 'center', minWidth: 210, fixed: 'right'},
            ]]
        });
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('state')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#RoleTable').trigger('reload');
                }); else {
                    $('#RoleTable').trigger('reload')
                }
                return false;
            }, false);
        });

    });

</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('已激活')}|{:lang('已禁用')}" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">{:lang("已激活")}</b>' : '<b class="color-red">{:lang("已禁用")}</b>'}}
    <!--{/if}-->
</script>
<!-- 数据操作工具条模板 -->
<script type="text/html" id="toolbar">

    <a data-title="修改" class="layui-btn  layui-btn-sm layui-btn-warm" data-modal='{:url("edit")}?id={{d.id}}''>编辑</a>
    <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定删除吗?" data-action="{:url('remove')}" data-value="id#{{d.id}}">删除</a>

</script>
{/block}